package org.jeecg.modules.classrooms.property.service.impl;

import org.jeecg.modules.classrooms.property.entity.Property;
import org.jeecg.modules.classrooms.property.mapper.PropertyMapper;
import org.jeecg.modules.classrooms.property.service.IPropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Description: property
 * @Author: jeecg-boot
 * @Date:   2020-05-18
 * @Version: V1.0
 */
@Service
public class PropertyServiceImpl extends ServiceImpl<PropertyMapper, Property> implements IPropertyService {

    @Autowired
    private PropertyMapper propertyMapper;

    @Override
    public boolean save(Property entity) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("property_name",entity.getPropertyName());
        List<Property> properties = propertyMapper.selectByMap(map);
        if (properties.size() <= 0){
            return   super.save(entity);
        } else {
            Property property = properties.get(0);
            property.setPropertyNumber((Integer.parseInt(property.getPropertyNumber()) + Integer.parseInt(entity.getPropertyNumber()))+"");
            return  super.updateById(property);
        }

    }
}
